#ifndef Bileton_H
#define Bileton_H
#include <iostream>
#include <fstream>
#include <cstring>
#include <iomanip>
using namespace std;
const int BUFFER = 100;
class bilet {
private:
    char* name;
    int n_vagon;
    bool kupe;
    int place;
    static int clipoth;
    int id;
public:
    bilet(){
        this->name = nullptr;
        this->n_vagon = 0;
        this->kupe = false;
        this->place = 0;
        ++clipoth;
        id = clipoth;
        cout << "Создание ID " << id << endl;
    };
    bilet(char* name, int n_vagon, bool kupe, int place){
        int l_name = strlen(name) + 1;
        this->name = new char[l_name];
        strncpy(this->name, name, l_name);
        this->n_vagon = n_vagon;
        this->kupe = kupe;
        this->place = place;
        ++clipoth;
        id = clipoth;
        cout << "Создание ID " << id << endl;
    }
    ~bilet(){
        cout << "Удаление " << id << endl;
        delete[] name;
        --clipoth;
    };
    const char* getName(){
        return name;
    }
    int getn_vagon(){
        return n_vagon;
    }
    bool getkupe(){
        return kupe;
    }
    int getplace(){
        return place;
    }
    void setName(){
                        char buf[BUFFER];
                cout << "Введите новое имя пассажира\n";
                cin >> buf;
                int l_name = strlen(buf) + 1;
                delete[] name;
                name = new char[l_name];
                strncpy(name, buf, l_name);
    }
    void setn_vagon(){
                        int bufn_vagon;
                cout << "Ведите новый номер вагона\n";
                cin >> bufn_vagon;
                n_vagon = bufn_vagon;
    }
    void changekupe(){
                        if (kupe==false) {
                    kupe=true;
                    cout << "Ура, купе!\n";
                }
                else
                {
                    kupe=false;
                    cout << "Эх, теперь плацкарт...\n";
                }
    }
    void setplace(){
                        int bufplace;
                cout << "Введите номер места\n";
                cin >> bufplace;
                place = bufplace;
    }
   bilet &operator=(const bilet &other) {
        if (this != &other) {
            delete[] name;
        int l_name = strlen(other.name) + 1;
        name = new char[l_name];
        strncpy(name, other.name, l_name);
        n_vagon = other.n_vagon;
        kupe = other.kupe;
        place = other.place;
        }
        return *this;
 }
    bool operator>(const bilet &other) {
        return this->n_vagon > other.n_vagon;
        }
    bool operator==(const bilet &other) {
        return this->n_vagon == other.n_vagon;
        }
    void edit2(){
        print();
        cout << "Что вы хотите поменять?(1 для смены имени, 2 для смены номера вагона, 3 для смены типа, 4 для смены места\n";
        int integer;
        cin >> integer;
        switch(integer){
            case 1: {
                setName();
                break;
            }
            case 2: {
                setn_vagon();
                break;
            }
            case 3: {
                changekupe();
                break;
            }
            case 4: {
                setplace();
                break;
            }
            default: cout << "Ок, ну, всегда можешь передумать\n";
                break;
            }
        }
    
    void print(){
       cout << "Имя пассажира: " << getName() << "\t" << "Вагон номер: " << getn_vagon() << "\t" << "Купе? " << getkupe() << "\t"<< "Номер места: " << getplace() << endl;
  };
};
ofstream &operator<<(ofstream &out, bilet &bilet);
ifstream &operator>>(ifstream &in, bilet &bilet);
int menu2();
void read_database2(const char *& filename, bilet *& bilets, int & bilets_count);
void write_database2(const char *& filename, bilet *& bilets, int & bilets_count);
void sort_database2(bilet *& bilets, const int & bilets_count); // 
void add2(bilet *& bilets, int &bilets_count);
void remove2(bilet *& bilets, int & bilets_count, const int & id);
void print_database2(bilet *& bilets, const int &bilets_count);
int find2(bilet *& bilets, const int & bilets_count);
#endif